import {getRoleInfo} from '../../utils/api/role.js'

const role = {
    state : {
        allSysRoles : [],
        allSysRoleNames : []
    },
    mutations : {
        SET_SYSYROLE : (state,allSysRoles) =>{
            state.allSysRoles = allSysRoles;
        },
        SET_ROLENAME : (state,allSysRoleNames) =>{
            state.allSysRoleNames = allSysRoleNames;
        }
    },
    actions : {
        /**
         * 获取系统角色
         */
        GetRoleInfo : ({commit}) => {
            return new Promise((resolve,reject) => {
                getRoleInfo().then(res =>{
                    var allSysRoleNames = [];
                    res.data.rows.forEach((item) => {
                        allSysRoleNames.push(item.roleName);
                    });
                    commit('SET_SYSYROLE',res.data.rows);
                    commit('SET_ROLENAME',allSysRoleNames);
                    resolve(res);
                }).catch(err =>{
                    reject(err);
                });
            })
        }
    }
}

export default role